package com.apexbrain.apexbrainserver.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * 用户回答问题情况表tb_question_answer的mapper
 */
@Mapper
public interface QuestionAnswerMapper
{
    /**
     * 获得用户的回答，如果还没回答则返回null
     * @param userId 用户的用户名
     * @param questionId 问题的id
     * @return answer字段
     */
    @Select("select answer from tb_question_answer " +
            "where user_id = ${userId} and question_id = ${questionId}")
    String getAnswer(String userId, int questionId);

    /**
     * 插入用户回答答案
     * @param userId 用户的用户名
     * @param questionId 问题的id
     * @param answer 用户的答案
     * @return 插入是否成功
     */
    @Insert("insert into tb_question_answer values(${userId}, ${questionId}, ${answer})")
    boolean addAnswer(String userId, int questionId, String answer);

    /**
     * 删除用户的对战答题记录
     * @param userId 用户的用户名
     * @return 删除是否成功
     */
    @Delete("delete from tb_question_answer where user_id = ${userId}")
    boolean eraseAnswers(String userId);
}
